/*
 * @Author: chengwenixng
 * @Date: 2021-08-02 20:32:25
 * @LastEditors: g05047
 * @LastEditTime: 2021-08-07 16:31:51
 * @Description: file content
 */
import request from '@utils/request';
import * as actionTypes from './actionType'
import { message } from 'antd';

//获取所有数据
export const getAccountConfigDatasRequest = () => {
    return (dispatch) => {
        request('POST', '/api/server/web/rest/user/findBasicData', {
            cmd: 'findBasicData',
            type: 'request',
            request: {}
        }).then(obj => {
            let res = obj.response;
            if (res.res) {
                let adminDatas = res.adminDatas;
                let otherUserData = res.otherUserData;
                dispatch(getAccountConfigDatas(adminDatas,otherUserData));
            } else {
                message.error('获取数据失败！' + res.exception, 1);
            }
        }).catch(err => console.log(err));
    }
}
const getAccountConfigDatas = (adminDatas, otherUserData) => ({
    type: actionTypes.ADMINDATAS,
    adminDatas, otherUserData
})

//删除用户
export const deleteBasicDataRequest = (idList) => {
    return (dispatch) => {

        request('POST', '/api/server/web/rest/user/deleteBasicData', {
            cmd: 'deleteBasicData',
            type: 'request',
            request: {
                ...idList
            }
        }).then(obj => {
            let res = obj.response;
            if (res.res) {
                message.success('删除路由成功', 1);
                dispatch(getAccountConfigDatasRequest ())
            } else {
                message.error('删除路由失败' + res.exception, 1);
            }
        }).catch(err => console.log(err));
    }
}
//开始授权
export const startAuthorization = (id) => {
    return (dispatch) => {

        request('POST', '/api/server/web/rest/user/startAuthorization', {
            cmd: 'startAuthorization',
            type: 'request',
            request: {
                id
            }
        }).then(obj => {
            let res = obj.response;
            if (res.res) {
                message.success('授权成功！', 1);
                dispatch(getAccountConfigDatasRequest ())
            } else {
                message.error(res.exception);
            }
        }).catch(err => console.log(err));
    }
}

